package com.soulkun.smarthome.ui.main.home.adapter

import android.content.Context
import android.view.View
import androidx.databinding.ObservableArrayList
import androidx.databinding.ViewDataBinding
import androidx.recyclerview.widget.LinearLayoutManager
import com.soulkun.smarthome.R
import com.soulkun.smarthome.databinding.AppRecycleItemMainHomeDeviceHistoryDataListBinding
import com.soulkun.smarthome.databinding.AppRecycleItemMainHomeDeviceRecentDataListBinding
import com.soulkun.smarthome.logic.dto.DeviceDataDTO
import com.soulkun.smarthome.logic.vo.DeviceDataHistoryVO
import soulkun.library.mvvm.adapter.BaseDataBindingRecyclerViewAdapter

class AppMainHomeDeviceHistoryDataListAdapter(
    context: Context,
    dataList: ObservableArrayList<DeviceDataHistoryVO>,
    private val onClickListener: (ViewDataBinding) -> View.OnClickListener
) : BaseDataBindingRecyclerViewAdapter<DeviceDataHistoryVO>(context, dataList) {

    override fun getContentLayoutResId(): Int {
        return R.layout.app_recycle_item_main_home_device_history_data_list
    }

    override fun setContentViewHolderCreateListener(binding: ViewDataBinding) {
        (binding as AppRecycleItemMainHomeDeviceHistoryDataListBinding).onClickListener = onClickListener(binding)
    }

    override fun setContentViewHolderBindListener(binding: ViewDataBinding, dataPosition: Int) {
        (binding as AppRecycleItemMainHomeDeviceHistoryDataListBinding).deviceDataHistoryVO =
            dataList[dataPosition]
        binding.rvMainHomeDeviceHistoryDataListListItem.run {
            layoutManager = LinearLayoutManager(context)
            adapter = AppMainHomeDeviceHistoryDataItemListAdapter(context, dataList[dataPosition].dataHistoryList)
        }
    }

}